package likou;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2021/11/29 13:15
 */
public class _1058 {
    public static void main(String[] args) {
        _1058 one = new _1058();
        System.out.println(one.minimizeError(new String[]{
                "0.700","2.800","4.900"
        },8));
    }
    public String minimizeError(String[] prices, int target) {
        List<Integer> list = new ArrayList<>();
        for(String str:prices){
            String[] spli = str.split("\\.");
            target-= Integer.valueOf(spli[0]);
            int last = Integer.valueOf(spli[1]);
            if(last>0){
                list.add(last);
            }
        }
        list.sort(Comparator.comparingInt(i2 -> i2));
        double res = 0.0;
        int i = list.size()-1;
        for(;i>=0&&target>0;i--,target--){
            res += (1000-list.get(i));
        }
        for(;i>=0;i--){
            res += list.get(i);
        }
        return String.valueOf(res/1000);
    }
}
